/**@file
   Physical address accessing class.
   
   @par license 
   Copyright 2012 Lu, Ken. All rights reserved.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 
   @author: Lu, Ken (bluewish.ken.lu@gmail.com)
**/

#include "phymem.h"

#ifdef _MSC_VER
#include "kstub.h"
#endif // _MSC_VER

namespace ken {

#ifdef _MSC_VER

//
// Implement class
//
class u_MmIO::Impl
{
public:
    u_MmIO::Impl::Impl() {}
    u_MmIO::Impl::~Impl() {}

    void read(un_t base, u32_t &length, u8_t* out) {
        u_KStubDev::instance()->mmioread(base, length, out);
    }

    void write(un_t base, u32_t length, u8_t* in) {
        u_KStubDev::instance()->mmiowrite(base, length, in);
    }

    void scan(un_t base, u32_t length, u8_t* inbuf, u32_t inbuflen, un_t &first) {
        u_KStubDev::instance()->mmioscan(base, length, inbuf, inbuflen, first);
    }

private:
    DISALLOW_COPY_AND_ASSIGN(Impl);
};

#endif // _MSC_VER
//
// TODO: implement linux verion later by using inw_p, inc_p, outc_p, outw_p.
//


u_MmIO::u_MmIO():pImpl_(new Impl()) 
{
}

u_MmIO::~u_MmIO()
{
    delete pImpl_;
}

void u_MmIO::read(un_t base, u32_t &length, u8_t* out)
{
    pImpl_->read(base, length, out);
}

void u_MmIO::write(un_t base, u32_t length, u8_t* in)
{
    pImpl_->write(base, length, in);
}

void u_MmIO::scan(un_t base, u32_t length, u8_t* inbuf, u32_t inbuflen, un_t &first)
{
    pImpl_->scan(base, length, inbuf, inbuflen, first);
}

} // namespace
